package com.xiyu.service.repository.material.info;

import com.xiyu.service.vo.material.materialInfo.MaterialInfoListQueryCategoryInput;
import com.xiyu.service.model.material.info.MaterialCategory;
import com.xiyu.service.model.material.info.MaterialCategoryTable;
import org.babyfish.jimmer.spring.repository.JRepository;
import org.springframework.util.StringUtils;
import java.util.Optional;
import java.util.List;

public interface MaterialCategoryRepository extends JRepository<MaterialCategory, Long> {
    MaterialCategoryTable materialCategoryTable = MaterialCategoryTable.$;

    default List<MaterialCategory> listQueryCategory(MaterialInfoListQueryCategoryInput inputVO){
        return sql().createQuery(materialCategoryTable)
                .whereIf(StringUtils.hasText(inputVO.getCategoryName()), () -> materialCategoryTable.categoryName().like(inputVO.getCategoryName()))
                .orderBy(materialCategoryTable.id().desc())
                .select(materialCategoryTable).execute();
    }

    Optional<MaterialCategory> findFirstByCategoryName(String categoryName);


}